// BIMFACE 数据服务-单模型数据相关接口
// https://bimface.com/docs/model-data-service/v1/api-reference/getElementIdsUsingGET.html

import  bimfaceHttp from '@/api/Bimface';

enum Api {
  Files = '/data/v2/files',
  Query = '/data/v2/query',
}

/**
 * @todo: interface待实现
 * @abstract: 查询满足条件的构件
 */
export function getSplitResult(fileId: number, params: object) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/elementIds`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 查询符合条件的构件ID列表
 * @description: 查询符合条件的构件ID列表，支持基于DSL进行组合查询，具体可参考文档。若需根据修改后的属性值查询，需要设置请求参数includeOverrides的值为true。
 */
export function queryElementIds(
  params: {
    includeOverrides?: boolean;
  },
  data: any,
) {
  return bimfaceHttp.post<any>({
    timeout: 30 * 60 * 1000,
    url: Api.Query + `/elementIds`,
    params: params,
    data: data,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 获取构件材质
 */
export function getMaterials(fileId: number, elementId: string) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/elements/${elementId}/materials` });
}

/**
 * @todo: interface待实现
 * @abstract: 获取构件属性
 */
export function getAttributes(
  fileId: number,
  elementId: string,
  params: {
    includeOverrides?: boolean;
  },
) {
  return bimfaceHttp.get<any>({
    url: Api.Files + `/${fileId}/elements/${elementId}`,
    params: params,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 获取多个构件共同属性
 * @description: 若传入的elementId不止一个，则返回这些elementId共同的属性，共同的定义为：属性key与value都相等
 */
export function getCommonAttributes(
  fileId: number,
  params: {
    elementIds: string[];
    includeOverrides?: boolean;
  },
) {
  return bimfaceHttp.get<any>({
    url: Api.Files + `/${fileId}/commonElementProperties`,
    params: params,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 批量获取属性
 * @description: 在请求体里可以传入构件ID列表来批量获取属性，单次请求的构件数量上限为1000。若需根据修改后的属性值查询，需要设置请求参数includeOverrides的值为true。
 */
export function getAttributesInBatches(
  fileId: number,
  params: {
    includeOverrides?: boolean;
  },
  data: {
    filter: {
      keys: string[];
      group: string;
    }[];
    elementIds: string[];
  },
) {
  return bimfaceHttp.post<any>({
    url: Api.Files + `/${fileId}/elements`,
    params: params,
    data: data,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 获取单模型楼层信息
 */
export function getFloorsInSingleModel(
  fileId: number,
  params: {
    includeArea: boolean;
    includeRoom: boolean;
  },
) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/floors`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 获取多模型楼层信息
 */
export function getFloorsInMultiModel(
  fileIds: string,
  params: {
    includeArea: boolean;
    includeRoom: boolean;
  },
) {
  return bimfaceHttp.get<any>({
    url: Api.Files + `/${fileIds}/fileIdfloorsMappings`,
    params: params,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 获取模型链接信息
 */
export function getModelLinks(fileId: number) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/links` });
}

/**
 * @todo: interface待实现
 * @abstract: 获取单个房间信息
 */
export function getRooms(
  fileId: number,
  roomId: string,
  params: {
    fileId: number;
    roomId: string;
  },
) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/rooms/${roomId}`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 获取楼层对应面积分区列表
 */
export function getFloorsAreaZonlingList(
  fileId: number,
  params: {
    floorId: string;
  },
) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/areas`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 获取单个面积分区信息
 */
export function getAreaZonling(fileId: number, areaId: string) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/areas/${areaId}` });
}

/**
 * @todo: interface待实现
 * @abstract: 获取构件分类树
 * @description: 单模型构件分类树, treeType接受两个值：default和customized,默认为default. v参数用来区别treeType为default时返回树的格式, customized总是返回格式2.0的构件树. 当treeType为"customized"时：desiredHierarchy表示了筛选树的层次,可选值有building,systemType,specialty,floor,category,family,familyType，如:desiredHierarchy=specialty,systemtype ；customizedNodeKeys: 用来指定筛选树每个维度用id或者是name作为唯一标识, 如"floor":"id"。
 */
export function getComponentClassificationTree(
  fileId: number,
  params: {
    treeType?: string;
    v?: string;
  },
  data: {
    customizedNodeKeys?: any;
    desiredHierarchy?: Array<object>;
  },
) {
  return bimfaceHttp.post<any>({ url: Api.Files + `/${fileId}/tree`, params: params, data: data });
}

/**
 * @todo: interface待实现
 * @abstract: 获取三维视点或二维视图列表
 */
export function get3DViewpointsOr2DViewsList(fileId: number) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/views` });
}

/**
 * @todo: interface待实现
 * @abstract: 获取MEP系统信息
 */
export function getMEPSystem(
  fileId: number,
  params: {
    systemCategory?: string;
    systemType?: string;
  },
) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/MEPSystem`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 获取图纸列表
 */
export function getDrawingsheets(
  fileId: number,
  params: {
    elementId?: string;
  },
) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/drawingsheets`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 修改单模型指定构件属性
 */
export function updateSingleModelAttribute(
  fileId: number,
  elementId: string,
  data: {
    items?: {
      extension: object;
      unit: string;
      code: string;
      orderNumber: number;
      valueType: number;
      value: object;
      key: string;
    }[];
    group?: string;
  },
) {
  return bimfaceHttp.put<any>({
    url: Api.Files + `/${fileId}/elements/${elementId}/properties`,
    data: data,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 删除单模型指定构件属性
 */
export function deleteSingleModelAttribute(
  fileId: number,
  elementId: string,
  data: {
    items?: {
      extension: object;
      unit: string;
      code: string;
      orderNumber: number;
      valueType: number;
      value: object;
      key: string;
    }[];
    group?: string;
  },
) {
  return bimfaceHttp.delete<any>({
    url: Api.Files + `/${fileId}/elements/${elementId}/properties`,
    data: data,
  });
}

/**
 * @todo: interface待实现
 * @abstract: 根据楼层ID或构件ID获取对应房间列表
 */
export function getRoomsByFloorOrComponent(
  fileId: number,
  params: {
    elementId?: string;
    floorId?: string;
    roomToleranceXY?: string; // enum (STRICT, ORDINARY, LENIENT)
    roomToleranceZ?: string; // enum (STRICT, ORDINARY, LENIENT)
  },
) {
  return bimfaceHttp.get<any>({ url: Api.Files + `/${fileId}/rooms`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 查询指定构件属性的所有值
 * @description: 查询指定构件属性的所有值，目前目标类型仅支持file
 */
export function getSpecifiedComponentAllAttributesValue(params: {
  includeOverrides?: boolean;
  properties: string[];
  targetIds: string[];
}) {
  return bimfaceHttp.get<any>({ url: Api.Query + `/propertyValues`, params: params });
}

/**
 * @todo: interface待实现
 * @abstract: 生成分页查询的ContextId
 */
export function getContextId() {
  return bimfaceHttp.get<any>({ url: Api.Query + `/paginationContextId` });
}
